package com.taiji.dicom4cloud.admin.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taiji.dicom4cloud.admin.config.MqttGateway;
import com.taiji.dicom4cloud.smart.rfid.mqtt.Exchange;
import com.taiji.dicom4cloud.smart.rfid.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class RfidController {
    @Autowired
    private MqttGateway mqttGateway;

    @PostMapping(value = "/rfid/exchange")
    public CommonResult<?> exchange(@Valid @RequestBody Exchange<String> data) {
        String topic = String.format("command/%s", data.getClientId());
        mqttGateway.send2Mqtt(topic, JSON.toJSONString(data));
        return CommonResult.success();
    }
}
